package com.zygh.policeasset.controller;

import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.Menu;
import com.zygh.policeasset.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/menu"})
@Api(tags = {"菜单权限管理模块"}, description = "MenuController")
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/MenuController.class */
public class MenuController {
    @Autowired
    private MenuService menuService;

    @RequestMapping(value = {"/findAllMenu"}, method = {RequestMethod.GET})
    @ApiOperation("查询所有菜单")
    public Object findAllMenu() {
        return this.menuService.findAllMenu();
    }

    @RequestMapping(value = {"/addMenu"}, method = {RequestMethod.POST})
    @ApiOperation("添加菜单")
    public Object addMenu(@RequestBody Menu menu) {
        if (this.menuService.addMenu(menu).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加菜单错误");
    }

    @RequestMapping(value = {"/deleteMenu"}, method = {RequestMethod.POST})
    @ApiOperation("删除菜单")
    public Object deleteMenu(@RequestBody Menu menu) {
        if (this.menuService.findParent(menu.getId()).size() >= 1) {
            return new CommonResult().validateFailed("此菜单下有子菜单禁止删除");
        }
        if (this.menuService.deleteMenu(menu.getId()).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除菜单错误");
    }

    @RequestMapping(value = {"/updateMenu"}, method = {RequestMethod.POST})
    @ApiOperation("修改菜单")
    public Object updateMenu(@RequestBody Menu menu) {
        if (this.menuService.updateMenu(menu).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改菜单错误");
    }
}